package com.hong.garen.conn;
/**
 * Created by GarenHong  on 2023/2/25.
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class connection {
    Connection dbconn = null;
    public Connection getConnection2(){
        String driver6 = "com.mysql.cj.jdbc.Driver";
        String driver5 = "com.mysql.jdbc.Driver";
        String dburl = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8";
        String username = "root";
        String password = "123456";
        try {
            //加载驱动
            Class.forName(driver5);
            //创建连接对象
            dbconn = DriverManager.getConnection(dburl,username,password);
            return dbconn;

        }catch (ClassNotFoundException e){
            System.out.println(e);
            System.out.println("驱动程序类没有找到");
            return null;

        }catch (SQLException e1){
            System.out.println(e1);
            return null;
        }

    }

    public void destroy(){
        try{
            dbconn.close();

        }catch (Exception e2){
            e2.printStackTrace();
        }
    }




}
